package pers.xusuona.connectAPI;

import java.net.URLEncoder;

public class GetResult {
	public static String detect(String filePath)
	{
		// 请求url
//		String filePath = "D:\\BaiduAPI\\8.jpg";
		String url = "https://aip.baidubce.com/rest/2.0/image-classify/v1/plant";
		try {
			String image = Base64Util.encode(FileUtil.readFileByBytes(filePath));
			String imgParam = URLEncoder.encode(image, "UTF-8");
			String param = "image=" + imgParam;

			// 注意这里仅为了简化编码每一次请求都去获取access_token，线上环境access_token有过期时间，
			// 客户端可自行缓存，过期后重新获取。
			String accessToken = AuthService.getAuth();

			String result = HttpUtil.post(url, accessToken, param);
//			System.out.println("返回结果：" + result);
			return result;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}
//	public static void main(String[] args) {
//		detect();
//	}

}
